package com.ssm.zyn.service.impl;
import com.ssm.zyn.dao.AnswerMapper;
import com.ssm.zyn.eo.AnswerEOpage;
import com.ssm.zyn.model.Answer;
import com.ssm.zyn.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实现业务及流程接口当中的内容
 */
@Service
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    private AnswerMapper answerMapper;

    /**
     *答题添加方法实现
     * @param answer 答题主题
     * @return 添加是否成功
     */
    @Override
    public int AddAnswer(Answer answer) {
        int isInsert=0;
        isInsert=answerMapper.insertAnswer(answer);
        return isInsert;
    }

    /**
     *答题更新方法实现
     * @param answer 答题主题
     * @return 更新是否成功（-1：更新执行SQL报错）
     */
    @Override
    public int UpdateAnswer(Answer answer) {
        int isUpdate = 0;
        /*1.没有相关业务流程的判断*/
        try {
            isUpdate = answerMapper.updateAnswer(answer);
        } catch (Exception e) {
            isUpdate = -1;
            //打印更新时报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因为"+e.getMessage());
        }
        return isUpdate;
    }

    /**
     * 答题删除方法实现
     * @param aid 主键
     * @return 删除是否成功
     */
    @Override
    public int DeleteAnswer(int aid) {
        int delAnswer=0;
        try{
            delAnswer=answerMapper.delAnswer(aid);
        }catch (Exception e){
            delAnswer=-1;
            System.out.println("删除班级信息时执行SQL报错，信息为"+e.getMessage());
        }
        return delAnswer;
    }

    /**
     *
     * @param answerEOpage
     * @return
     */
    @Override
    public List<AnswerEOpage> getWhereAll(AnswerEOpage answerEOpage) {
        List<AnswerEOpage> listAnswer= answerMapper.getWhereAll(answerEOpage);
        return listAnswer;
    }
}
